//
//  HNSH_LoginHomeViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/22.
//

#import "HNSH_LoginHomeViewController.h"

#import "YYText.h"

//vc
#import "ST_BaseWebController.h"
#import "HNSH_LoginViewController.h"

@interface HNSH_LoginHomeViewController ()

/** */
@property (nonatomic, strong)UIButton * phoneLoginBtn;
/** */
@property (nonatomic, strong)UIButton * wxLoginBtn;
/** */
@property (nonatomic, strong)YYLabel * desLabel;

@end

@implementation HNSH_LoginHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor appWhiteLabelColor];
    [self configUI];
}

- (void)configUI {
//    UIImageView *topImgV = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenWidth-168)/2, kNavBarAndStatusBarHeight + 9, 253, 84)];
//    topImgV.image = [UIImage imageNamed:@"mine_about_icon"];
//    [self.view addSubview:topImgV];
//
    UIImageView *centerImgV = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth/2-50, kNavBarAndStatusBarHeight + 126, 82, 82)];
    centerImgV.image = [UIImage imageNamed:@"login_home_center_icon"];
    [self.view addSubview:centerImgV];
    
    [self.view addSubview:self.wxLoginBtn];
    [self.view addSubview:self.phoneLoginBtn];
    [self.view addSubview:self.desLabel];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(-(kBottomSafeHeight + 30));
        make.height.mas_equalTo(14);
    }];
    
    [self.phoneLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-(kBottomSafeHeight + 300));
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(50);
    }];
    
    [self.wxLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.phoneLoginBtn.mas_top).offset(-13);
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(50);
    }];
}

#pragma mark lazy
- (UIButton *)phoneLoginBtn{
    if (!_phoneLoginBtn) {
        _phoneLoginBtn = [UIButton new];
        [_phoneLoginBtn setTitle:@"手机号登录" forState:UIControlStateNormal];
        [_phoneLoginBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _phoneLoginBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _phoneLoginBtn.backgroundColor = [UIColor appGreenColor];
        _phoneLoginBtn.layer.cornerRadius = 8.0f;
        _phoneLoginBtn.layer.masksToBounds = YES;
        [[_phoneLoginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            HNSH_LoginViewController *vc = [[HNSH_LoginViewController alloc]init];
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
    }
    return _phoneLoginBtn;
}

- (UIButton *)wxLoginBtn{
    if (!_wxLoginBtn) {
        _wxLoginBtn = [UIButton new];
//        [_wxLoginBtn setImage:[UIImage imageNamed:@"login_home_wx_icon"] forState:UIControlStateNormal];
        [_wxLoginBtn setTitle:@"微信登录" forState:UIControlStateNormal];
        [_wxLoginBtn setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
        _wxLoginBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _wxLoginBtn.backgroundColor = [UIColor appWhiteLabelColor];
        _wxLoginBtn.layer.cornerRadius = 8.0f;
        _wxLoginBtn.layer.masksToBounds = YES;
        _wxLoginBtn.layer.borderColor = [[UIColor appGreenColor] CGColor];
        _wxLoginBtn.layer.borderWidth = 1.0f;
//        [_wxLoginBtn addTarget:self action:@selector(sendBtnAction) forControlEvents:UIControlEventTouchUpInside];
//        _wxLoginBtn.hidden = YES;
//        [_wxLoginBtn HNSH_layoutButtonWithEdgeInsetsStyle:HHZXButtonStyleTextRight imageTitleSpace:8];
    }
    return _wxLoginBtn;
}

- (YYLabel *)desLabel{
    if (!_desLabel) {
        _desLabel = [YYLabel new];
        _desLabel.font = [UIFont systemFontOfSize:14];
        _desLabel.textColor = [UIColor appGray666LabelColor];
        _desLabel.numberOfLines = 0;
        [self setDefaultText];
    }
    return _desLabel;
}


- (void)setDefaultText{
    NSMutableAttributedString * text = [[NSMutableAttributedString alloc] initWithString:@"登录即代表同意"];
    //设置文本字号
    text.yy_font = [UIFont systemFontOfSize:10];
    //设置字体颜色
    text.yy_color = [UIColor appGray666LabelColor];
    {
        NSMutableAttributedString *one = [[NSMutableAttributedString alloc] initWithString:@"《慧农生活用户协议》"];
        one.yy_font = [UIFont systemFontOfSize:10];
        one.yy_color = [UIColor appBlueLabelColor];
        [one yy_setTextHighlightRange:one.yy_rangeOfAll color:[UIColor appBlueLabelColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
            NSString *urlString = k_user_service;
            if ([[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID]) {
                NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID];
                if ([dict[@"user_service_url"] isNotBlank]) {
                    urlString = [NSString stringWithFormat:@"%@",dict[@"user_service_url"]];
                }
            }
            ST_BaseWebController * vc = [ST_BaseWebController new];
            vc.titleString = @"万物悦享用户协议";
            [vc loadURLString:urlString];
            [self.navigationController pushViewController:vc animated:YES];
        }];
        [text appendAttributedString:one];
    }
    {
        NSMutableAttributedString *one = [[NSMutableAttributedString alloc] initWithString:@"和"];
        one.yy_font = [UIFont systemFontOfSize:10];
        one.yy_color = [UIColor appGray666LabelColor];
        [text appendAttributedString:one];
    }
    {
        NSMutableAttributedString *one = [[NSMutableAttributedString alloc] initWithString:@"《慧农生活隐私协议》"];
        one.yy_font = [UIFont systemFontOfSize:10];
        one.yy_color = [UIColor appBlueLabelColor];
        [one yy_setTextHighlightRange:one.yy_rangeOfAll color:[UIColor appBlueLabelColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
            NSString *urlString = k_user_privacy;
            if ([[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID]) {
                NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:KSaveProtocolAddressID];
                if ([dict[@"privacy_url"] isNotBlank]) {
                    urlString = [NSString stringWithFormat:@"%@",dict[@"privacy_url"]];
                }
            }
            ST_BaseWebController * vc = [ST_BaseWebController new];
            vc.titleString = @"万物悦享隐私协议";
            [vc loadURLString:urlString];
            [self.navigationController pushViewController:vc animated:YES];
        }];
        [text appendAttributedString:one];
    }
    self.desLabel.attributedText = text;
    self.desLabel.textAlignment = NSTextAlignmentCenter;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
